<!--
* description: 新增编辑-审核意见
-->
<template>
  <section class="editBigAreaInfo">
    <el-dialog
      v-dialogDrag
      :close-on-click-modal="false"
      title="审核意见"
      :append-to-body="true"
      :visible.sync="curPopupsVisible"
      width="50%"
      @close="closeEdit"
      @open="open"
    >
      <dialogHeader
        slot="title"
        title="审核意见"
        :style-type="$store.state.app.dialogType"
      />

      <div class="filter-container filter-params">
        <el-row ref="vailComponentList" :gutter="26">
          <component
            :is="comp.component"
            v-for="comp in tableComponents.filter((o) => o.isMust === true)"
            :ref="comp.isRequire ? comp.isRequire + comp.compKey : comp.compKey"
            :key="comp.compKey"
            :validrule="comp.validrule"
            :code-field="comp.codeField"
            :text-field="comp.textField"
            :popups-key="comp.compKey"
            :parent-fileds="comp.parentFileds || ''"
            :code="formField[comp.codeField]"
            :disabled="comp.disabled"
            :is-require="comp.isRequire"
            :is-mul="comp.isMul"
            :span="comp.span || 8"
            :label-name="comp.labelName"
            :lookuptype="comp.lookuptype"
            :date-options-type="comp.dateOptionsType"
            @changeCode="getComponentCode"
          />
        </el-row>
      </div>

      <div slot="footer" class="dialog-footer">
        <el-button
          v-for="comp in tableButtons"
          :key="comp.compKey"
          :type="comp.type"
          :icon="comp.icon"
          @click="comp.clickEvent"
          >{{ comp.text }}</el-button
        >
      </div>
    </el-dialog>
  </section>
</template>
<script>
import { formMixins } from "@/components/mixins/formMixins";

import { orgApis } from "@/api/paSparePartsManagement";

export default {
  components: {
    dialogHeader: () => import("@/components/dialogHeader"),
    mixButton: () => import("@/components/basicComponent/mixButton"),
  },

  // 组件混入对象
  mixins: [formMixins],

  props: {
    editRowData11: Object,
    type: String,
    curPopupsVisible: Boolean,
    // popupsVisible: { type: Boolean, default: false },
    // 从网格传入的编辑行数据(json)
    dynamicEditRowData: {
      type: Object,
      default: function () {
        return {};
      },
    },
  },

  data() {
    const viewPageCode = "bigAreaInfo-edit";
    return {
      // 动态组件-按钮
      tableButtons: [
        {
          compKey: "btnKey1",
          type: "primary",
          size: "small",
          icon: "iconfont  icon-preservation",
          clickEvent: () => this.save(),
          text: this.$t("sys.button.save") /* 保存*/,
          position: "right",
        },
        {
          compKey: "btnKey2",
          type: "",
          size: "small",
          icon: "iconfont icon-preservatio",
          clickEvent: () => this.closeEdit(),
          text: this.$t("sys.button.cancel"), // 取消
        },
      ],

      // 动态组件-查询条件
      tableComponents:
        this.$ConfigCache.CacheConfig.cacheData[viewPageCode] &&
        this.$ConfigCache.CacheConfig.cacheData[viewPageCode].formComponents
          .length > 0
          ? this.$ConfigCache.CacheConfig.cacheData[viewPageCode].formComponents
          : [
              {
                compKey: "compKey1",
                labelName: "审核意见",
                codeField: "remark",

                component: () =>
                  import("@/components/org/commonInput/textareaInput"),
                type: "inputText",
                span: 24,
                isMust: true,
              },
            ],

      // 标题
      textMap: {
        edit: "索赔申请单审核",
        add: "价格策略信息新增",
      },

      // 表单数据（无需赋值，由混入对象赋值）
      formField: this.$utils.getFormField(
        this,
        {
          remark: "",
        },
        this.$ConfigCache.CacheConfig.cacheData[viewPageCode]
      ),
    };
  },

  methods: {
    open() {
      this.formField.remark = "";
    },
    // 关闭弹窗
    // handleClose(done) {
    //   this.$confirm('还未保存，确认关闭窗口？')
    //     .then(_ => {
    //       this.$emit('update:curPopupsVisible', false)
    //       done()
    //     })
    //     .catch(_ => {})
    // },
    closeEdit() {
      this.$emit("curPopupsVisible", false), (this.curPopupsVisible = false);
    },
    // 新增/编辑保存按钮
    save() {
      const that = this;
      this.$utils.validataMoth(this, "validpopup");
      if (this.valid) {
        if (this.type == "1") {
          //通过
          that.editSave(orgApis.purchaseClaimReviewPass);
        } else {
          that.editSave(orgApis.purchaseClaimReviewReject);
        }
      }
    },

    // 编辑保存
    editSave(api) {
      this.formField.claimOrderId=this.editRowData11.claimOrderId
      const that = this;
      const queryObj = {
        // 保存mutation
        type: "mutation",
        // api配置
        apiConfig: api,
        // 条件/实体参数（变量），根据typeParam中的定义配置
        variables:  that.formField,
      };
      // 转换了中台请求格式数据
      var paramD = that.$getParams(queryObj);
      // 调用中台API方法（可复用）
      that.$requestAPI(paramD).then((response) => {
        if (response.result === "1") {
          that.$message({
            message: response.msg /* 保存成功*/,
            type: "success",
            duration: 1000,
          });
          that.curPopupsVisible = false;
          that.$parent.$parent.popupsVisible = false;
          that.$nextTick(() => {
            that.$parent.$parent.$parent.queryTable(1);
          });
        } else {
          // 保存失败
          that.$message({
            message: response.msg,
            type: "warn",
            uration: 1000,
          });
        }
        that.curPopupsVisible = false;
      });
    },

    // 新增保存
    addSave() {
      const that = this;
      const queryObj = {
        // 保存mutation
        type: "mutation",
        // api配置
        apiConfig: {
          ServiceCode: "addBigArea",
          APIUrl: "/mp/e3sh/basics/ve/bigareaService/addBigArea.do",
        },
        // 条件/实体参数（变量），根据typeParam中的定义配置
        variables: that.formField,
      };
      // 转换了中台请求格式数据
      var paramD = this.$getParams(queryObj);
      // 调用中台API方法（可复用）
      this.$requestAPI(paramD).then((response) => {
        if (response.result === "1") {
          this.$message({
            message: "添加成功",
            type: "success",
            duration: 1000,
          });
          this.curPopupsVisible = false;
          this.$nextTick(() => {
            this.$parent.queryTable(1);
          });
        } else {
          // 保存失败
          this.$message({
            message: "添加失败:" + response.msg,
            type: "warn",
            uration: 1000,
          });
        }
        this.curPopupsVisible = false;
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.promptSpan {
  position: absolute;
  bottom: 26px;
  right: 335px;
  color: #e70020;
}
</style>

